package com.mall.web.controller.business;

import com.mall.business.domain.entity.BusOrderLine;
import com.mall.business.service.BusOrderLineService;
import com.mall.common.annotation.Log;
import com.mall.common.core.controller.BaseController;
import com.mall.common.core.domain.AjaxResult;
import com.mall.common.core.page.TableDataInfo;
import com.mall.common.enums.BusinessType;
import com.mall.common.utils.poi.ExcelUtil;
import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 订单明细Controller
 *
 * @author zhonglin
 * @date 2020-05-24
 */
@Controller
@RequestMapping("/business/orderLine")
public class BusOrderLineController
    extends BaseController {

  private String prefix = "business/orderLine";

  @Autowired
  private BusOrderLineService busOrderLineService;

  @RequiresPermissions("business:orderLine:view")
  @GetMapping()
  public String orderLine() {

    return prefix + "/orderLine";
  }

  /**
   * 查询订单明细列表
   */
  @RequiresPermissions("business:orderLine:list")
  @PostMapping("/list")
  @ResponseBody
  public TableDataInfo list(BusOrderLine busOrderLine) {

    startPage();
    List<BusOrderLine> list = busOrderLineService.selectBusOrderLineList(busOrderLine);
    return getDataTable(list);
  }

  /**
   * 导出订单明细列表
   */
  @RequiresPermissions("business:orderLine:export")
  @Log(title = "订单明细", businessType = BusinessType.EXPORT)
  @PostMapping("/export")
  @ResponseBody
  public AjaxResult export(BusOrderLine busOrderLine) {

    List<BusOrderLine>      list = busOrderLineService.selectBusOrderLineList(busOrderLine);
    ExcelUtil<BusOrderLine> util = new ExcelUtil<BusOrderLine>(BusOrderLine.class);
    return util.exportExcel(list, "orderLine");
  }

  /**
   * 新增订单明细
   */
  @GetMapping("/add")
  public String add() {

    return prefix + "/add";
  }

  /**
   * 新增保存订单明细
   */
  @RequiresPermissions("business:orderLine:add")
  @Log(title = "订单明细", businessType = BusinessType.INSERT)
  @PostMapping("/add")
  @ResponseBody
  public AjaxResult addSave(BusOrderLine busOrderLine) {

    return toAjax(busOrderLineService.insertBusOrderLine(busOrderLine));
  }

  /**
   * 修改订单明细
   */
  @GetMapping("/edit/{orderLineId}")
  public String edit(@PathVariable("orderLineId") Long orderLineId,
                     ModelMap mmap) {

    BusOrderLine busOrderLine = busOrderLineService.selectBusOrderLineById(orderLineId);
    mmap.put("busOrderLine", busOrderLine);
    return prefix + "/edit";
  }

  /**
   * 修改保存订单明细
   */
  @RequiresPermissions("business:orderLine:edit")
  @Log(title = "订单明细", businessType = BusinessType.UPDATE)
  @PostMapping("/edit")
  @ResponseBody
  public AjaxResult editSave(BusOrderLine busOrderLine) {

    return toAjax(busOrderLineService.updateBusOrderLine(busOrderLine));
  }

  /**
   * 删除订单明细
   */
  @RequiresPermissions("business:orderLine:remove")
  @Log(title = "订单明细", businessType = BusinessType.DELETE)
  @PostMapping("/remove")
  @ResponseBody
  public AjaxResult remove(String ids) {

    return toAjax(busOrderLineService.deleteBusOrderLineByIds(ids));
  }

}
